<html>
<head><meta charset="utf-8"><title>diagnostics around `for&lt;&#x27;a&gt;` · t-compiler/wg-diagnostics · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/index.html">t-compiler/wg-diagnostics</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html">diagnostics around `for&lt;&#x27;a&gt;`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="147980489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/147980489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#147980489">(Nov 19 2018 at 17:20)</a>:</h4>
<p>So the PR <a href="https://github.com/rust-lang/rust/pull/55517" target="_blank" title="https://github.com/rust-lang/rust/pull/55517">https://github.com/rust-lang/rust/pull/55517</a> makes <em>some</em> attempt to give better diagnostics around <code>for&lt;'a&gt;</code> bounds, but there's still lots of room to go.</p>
<p>This feels like an area where I'd love to brainstorm how best to present things.</p>



<a name="147980502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/147980502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#147980502">(Nov 19 2018 at 17:20)</a>:</h4>
<p>One thing I found is that we need to do a much better job tracking "how we got to this constraint"</p>



<a name="147980531"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/147980531" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#147980531">(Nov 19 2018 at 17:21)</a>:</h4>
<p>Example of <a href="https://github.com/rust-lang/rust/blob/aae6a305691671ec0b846b0409f9136ffeb7b991/src/test/ui/hrtb/hrtb-exists-forall-trait-invariant.stderr" target="_blank" title="https://github.com/rust-lang/rust/blob/aae6a305691671ec0b846b0409f9136ffeb7b991/src/test/ui/hrtb/hrtb-exists-forall-trait-invariant.stderr">an error for which I would give a "B" grade</a>, roughly:</p>
<div class="codehilite"><pre><span></span>error: implementation of `Trait` is not general enough
  --&gt; $DIR/hrtb-exists-forall-trait-invariant.rs:28:5
   |
LL |     foo::&lt;()&gt;(); //~ ERROR not general enough
   |     ^^^^^^^^^
   |
   = note: Due to a where-clause on `foo`,
   = note: `()` must implement `Trait&lt;for&lt;&#39;b&gt; fn(std::cell::Cell&lt;&amp;&#39;b u32&gt;)&gt;`
   = note: but `()` only implements `Trait&lt;fn(std::cell::Cell&lt;&amp;&#39;0 u32&gt;)&gt;` for some lifetime `&#39;0`

error: aborting due to previous error
</pre></div>



<a name="147980593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/147980593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#147980593">(Nov 19 2018 at 17:22)</a>:</h4>
<p>Example where I felt at a loss as to <a href="https://github.com/rust-lang/rust/blob/aae6a305691671ec0b846b0409f9136ffeb7b991/src/test/ui/hrtb/hrtb-exists-forall-fn.stderr" target="_blank" title="https://github.com/rust-lang/rust/blob/aae6a305691671ec0b846b0409f9136ffeb7b991/src/test/ui/hrtb/hrtb-exists-forall-fn.stderr">how to do better without having better causal information</a>:</p>
<div class="codehilite"><pre><span></span>error[E0308]: mismatched types
  --&gt; $DIR/hrtb-exists-forall-fn.rs:17:34
   |
LL |     let _: for&lt;&#39;b&gt; fn(&amp;&#39;b u32) = foo(); //~ ERROR mismatched types
   |                                  ^^^^^ one type is more general than the other
   |
   = note: expected type `for&lt;&#39;b&gt; fn(&amp;&#39;b u32)`
              found type `fn(&amp;u32)`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
</pre></div>



<a name="147981659"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/147981659" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#147981659">(Nov 19 2018 at 17:42)</a>:</h4>
<p>For the first case, something like this reads a little clearer to me, though it's a tough one:</p>
<div class="codehilite"><pre><span></span>error: implementation of `Trait` is not general enough
  --&gt; $DIR/hrtb-exists-forall-trait-invariant.rs:28:5
   |
LL |     foo::&lt;()&gt;(); //~ ERROR not general enough
   |     ^^^^^^^^^
   |
   = note: `foo` expects generic type `T` to impl `fn(std::cell::Cell&lt;&amp;&#39;b u32&gt;)` for any lifetime `&#39;b`...
   = note: ...however, `()` implements `Trait` where `T` is `fn(std::cell::Cell&lt;&amp;&#39;b u32&gt;)` for some fixed...
   = note: ...lifetime `&#39;a` - `&#39;a` cannot simultaneously be fixed and equal to any given lifetime `&#39;b`.

error: aborting due to previous error
</pre></div>



<a name="147982255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/147982255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#147982255">(Nov 19 2018 at 17:54)</a>:</h4>
<p>Taking a similar idea for the second case:</p>
<div class="codehilite"><pre><span></span>error[E0308]: mismatched types
  --&gt; $DIR/hrtb-exists-forall-fn.rs:17:34
   |
LL |     let _: for&lt;&#39;b&gt; fn(&amp;&#39;b u32) = foo(); //~ ERROR mismatched types
   |                                  ^^^^^ one type is more general than the other
   |
   = note: expected type `fn(&amp;&#39;b u32)` for any given lifetime `&#39;b` but `foo` is generic over...
   = note: ...a concrete lifetime `&#39;a`. for some invocation of `foo`, `&#39;a` takes on a fixed lifetime...
   = note: ...and so returns `fn(&amp;&#39;a u32)` for that fixed lifetime but is being stored into a variable...
   = note: ...where `&#39;a` would need to equal to any given lifetime `&#39;b`.

error: aborting due to previous error
</pre></div>



<a name="147982264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/147982264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#147982264">(Nov 19 2018 at 17:55)</a>:</h4>
<p>Neither is perfect, but maybe it'll inspire a better idea.</p>



<a name="147990578"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/147990578" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#147990578">(Nov 19 2018 at 19:59)</a>:</h4>
<blockquote>
<p><code>foo</code> expects generic type <code>T</code> to impl <code>fn(std::cell::Cell&lt;&amp;'b u32&gt;)</code> for any lifetime <code>'b</code>...</p>
</blockquote>
<p>That doesn't quite sound right to me. That is, <code>()</code> is required to implement the trait <code>Trait&lt;X&gt;</code> for some type <code>X</code>, where the type <code>X</code> is <code>for&lt;'b&gt; fn(Cell&lt;&amp;'b u32)</code>.</p>
<p>In other words, I'm not sure what the <code>T</code> is in your message, but whatever it is it cannot "implement" <code>fn</code>, as that is a type, not a trait.</p>
<p>Still, I think there is room for improvement, and the terms "any lifetime" and "some fixed" are perhaps good choices.</p>



<a name="147991026"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/147991026" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> davidtwco <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#147991026">(Nov 19 2018 at 20:05)</a>:</h4>
<p>Yeah, my wording is a little off. I tried to hide the <code>for&lt;'a&gt;</code> part and write what that meant in words, and call the rest <code>T</code> (which obviously wouldn't work in an actual error). I think the key thing I felt was beneficial was trying to explain better why the one type is less general - I did that through the "it is/becomes some fixed thing" type of wording.</p>



<a name="147992968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/147992968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#147992968">(Nov 19 2018 at 20:34)</a>:</h4>
<p>part of the problem here is that we have to "soup up" the data we have at hand to really be able to tell what happened</p>



<a name="147993020"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/147993020" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#147993020">(Nov 19 2018 at 20:34)</a>:</h4>
<p>but it's good to brainstorm what we want the message to be first</p>



<a name="147993025"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/147993025" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#147993025">(Nov 19 2018 at 20:34)</a>:</h4>
<p>and then figure out how to get the data we need</p>



<a name="147993048"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/147993048" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#147993048">(Nov 19 2018 at 20:34)</a>:</h4>
<p>explaining bindings like this is interesting: it feels particularly hard, although I don't think it's particularly hard for people to understand when explained well</p>



<a name="152047499"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/152047499" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Alexander Regueiro <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#152047499">(Dec 17 2018 at 18:03)</a>:</h4>
<p>Has anyone considered factoring out diagnostics into its own crate in the library? Parts of it are quite a mess right now.</p>



<a name="152060081"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/152060081" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#152060081">(Dec 17 2018 at 20:59)</a>:</h4>
<p>how would such a new crate improve the mess?</p>



<a name="152067619"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/152067619" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#152067619">(Dec 17 2018 at 22:30)</a>:</h4>
<p>Which part of diagnostics would you want as a separate crate?</p>



<a name="152136880"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/152136880" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#152136880">(Dec 18 2018 at 20:45)</a>:</h4>
<p>I've definitely thought about it :)</p>



<a name="152136926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/152136926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#152136926">(Dec 18 2018 at 20:45)</a>:</h4>
<p>there exists e.g. <a href="https://crates.io/crates/codemap-diagnostic" target="_blank" title="https://crates.io/crates/codemap-diagnostic">https://crates.io/crates/codemap-diagnostic</a></p>



<a name="152136987"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/152136987" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#152136987">(Dec 18 2018 at 20:46)</a>:</h4>
<p>but I would want us to try to rethink some details of our impl more deeply</p>



<a name="152137001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/152137001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#152137001">(Dec 18 2018 at 20:46)</a>:</h4>
<p>still, I think that having separate crates with unit tests etc can be great for maintenance</p>



<a name="152137016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics%20around%20%60for%3C%27a%3E%60/near/152137016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/diagnostics.20around.20.60for.3C&#x27;a.3E.60.html#152137016">(Dec 18 2018 at 20:46)</a>:</h4>
<p>(but it also induces some burden, our processes aren't always the best here)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>